package com.lxxin.service;

import com.github.pagehelper.PageInfo;
import com.lxxin.annotation.ClearRedisCache;
import com.lxxin.pojo.Archives;
import com.lxxin.pojo.Blog;
import com.lxxin.pojo.Carousel;
import com.lxxin.pojo.Count;
import com.lxxin.pojo.queryvo.BlogManageQueryVo;
import com.lxxin.service.impl.BlogServiceImpl;
import com.lxxin.service.impl.TagServiceImpl;
import com.lxxin.service.impl.TypeServiceImpl;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

public interface BlogService {
    /**
     * 根据id查询博客
     * @param id
     * @return
     */
    @Cacheable(cacheNames = "cache")
    Blog findBlogById(Long id);

    /**
     * 根据Id获取并转换博客内容
     * @param id
     * @return
     */
    @Cacheable(cacheNames = "cache")
    Blog findAndConvertBlogById(Long id);

    /**
     * 查询首页博客分页列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Cacheable(cacheNames = "cache")
    PageInfo<Blog> findHomeBlogList(Integer currentPage, Integer pageSize);

    /**
     * 查询归档博客列表
     * @return
     */
    @Cacheable(cacheNames = "cache")
    List<Archives> findArchivesBlogList();

    /**
     * 查询最近更新的前top条推荐的博客
     * @param top
     * @return
     */
    @Cacheable(cacheNames = "cache")
    List<Blog> findTopRecommendBlogList(Integer top);

    /**
     * 查询博客搜索结果
     * @param currentPage
     * @param pageSize
     * @param search
     * @return
     */
    PageInfo<Blog> findSearchBlog(Integer currentPage, Integer pageSize, String search);

    /**
     * 通过标签Id查询博客列表
     * @param currentPage
     * @param pageSize
     * @param tagId
     * @return
     */
    @Cacheable(cacheNames = "cache")
    PageInfo<Blog>  findBlogByTagId(Integer currentPage, Integer pageSize, Long tagId);

    /**
     * 根据分类Id查询博客列表
     * @param currentPage
     * @param pageSize
     * @param typeId
     * @return
     */
    @Cacheable(cacheNames = "cache")
    PageInfo<Blog> findBlogByTypeId(Integer currentPage, Integer pageSize, Long typeId);

    /**
     * 查询博客、分类、标签总数
     * @return
     */
    @Cacheable(cacheNames = "count")
    Count findCount();

    /**
     * 根据博客id更新评论数
     * @param id
     * @param comments
     * @return
     */
    @ClearRedisCache
    Long updateComments(Long id, Long comments);

    /**
     * 根据博客id获取字数
     * @param id
     * @return
     */
    @Cacheable(cacheNames = "cache")
    Long findWordCount(Long id);

    /**
     * 根据博客id查询浏览次数并更新
     * @param id
     * @param isAdd
     * @return
     */
    Long findViewsById(Long id, Boolean isAdd);

    /**
     * 根据博客idlist查询浏览量list
     * @param ids
     * @return
     */
    List<Long> findViewsByIds(List<Long> ids);

    /**Long
     * 获取所有文章总字数
     * @return
     */
    @Cacheable(cacheNames = "cache")
    Long findAllWordCount();

//    -----------------------------------------后台功能---------------------------------------------

    /**
     * 查询博客列表
     * @param currentPage
     * @param pageSize
     * @return
     */
    @Cacheable(cacheNames = "cache")
    PageInfo<Blog> findBlogList(Integer currentPage, Integer pageSize, BlogManageQueryVo blogManageQueryVo);

    /**
     * 保存博客
     * @param blog
     * @return
     */
    @ClearRedisCache(cascade = {TagServiceImpl.class, TypeServiceImpl.class})
    int saveBlog(Blog blog);

    /**
     * 根据id更新博客信息
     * @param blog
     * @return
     */
    @ClearRedisCache(cascade = {TagServiceImpl.class, TypeServiceImpl.class})
    int updateBlog(Blog blog);

    /**
     * 根据id删除博客
     * @param id
     */
    @ClearRedisCache(cascade = {TagServiceImpl.class, TypeServiceImpl.class})
    void deleteBlog(Long id);

    /**
     * 查询轮播图列表
     * @return
     */
    @Cacheable(cacheNames = "cache")
    List<Carousel> findCarouselList();

    /**
     * 根据id查找轮播图
     * @param id
     * @return
     */
    @Cacheable(cacheNames = "cache")
    Carousel findCarouselById(Long id);

    /**
     * 保存轮播图
     * @param carousel
     * @return
     */
    @ClearRedisCache
    int saveCarousel(Carousel carousel);

    /**
     * 更新轮播图
     * @param carousel
     * @return
     */
    @ClearRedisCache
    int updateCarousel(Carousel carousel);

    /**
     * 删除轮播图
     * @param id
     */
    @ClearRedisCache
    void deleteCarousel(Long id);
}
